#Word order experiment

#Modules to import

import datetime
import time
import random
from random import shuffle
import xlwt
import xlrd
import xlutils
from xlutils import copy
from xlrd import open_workbook
import pandas as pd
import numpy as np

#PsychoPy
import psychopy
from psychopy import visual, core, event, gui
from psychopy.visual import Window, TextStim
from psychopy.core import wait
from psychopy.event import waitKeys


#--------------------------------------------------------------------------------------

#Functions

def timeNow(): #get current time
    now = datetime.datetime.now()
    return now

def getWindow(): #get window for experiment
    window = psychopy.visual.Window([1200,600], allowGUI=True, color=[0,0,1], units='pix') #add fullscr=True
    return window

def InstructionsStart(window, display_duration, now, sheet1): #annotate user sheet + display greeting on screen
    sheet1.write(1,6, now.strftime('%H:%M'))
    sheet1.write(1,8, now.strftime('%d-%m-%Y'))
    greet = psychopy.visual.TextStim(window, text = "Welcome to the experiment!")
    greet.draw() #draw the greeting
    window.flip()
    psychopy.core.wait(display_duration)
    return sheet1

def getStimuli(lines):
    stimuli = []
    for line in lines:
        line = line.strip()
        stimuli.append(line)
    setsize = len(stimuli)
    return stimuli, setsize

def displayDuration(): #get display duration/inter-stimulus interval (ISI) in seconds
    display_duration = 4500 #ms.
    ISI = 2000 #inter-stimulus interval in ms.
    display_duration = display_duration / 1000.0 #sec.
    ISI = ISI / 1000.0
    return display_duration, ISI


def learningPhase(window, ISI, stimuli, setsize, display_duration): #LEARNING PHASE
    begin = psychopy.visual.TextStim(window, text = "Learn the words that appear on the screen")
    begin.draw()
    window.flip()
    psychopy.core.wait(display_duration)
    for i in range(setsize):
        text_stimulus = psychopy.visual.TextStim(window, text = stimuli[i], height = 128) #height = font
        text_stimulus.draw()
        window.flip() 
        psychopy.core.wait(ISI)
    probe_instructions = psychopy.visual.TextStim(window, text = 'You will now be tested on the words you just learned.', wrapWidth = 50000)
    probe_instructions.draw()
    window.flip()
    psychopy.core.wait(display_duration)


def probeTrial(window, ISI, display_duration, probeAR): #TESTING PHASE
    probe_message = psychopy.visual.TextStim(window, text = 'In which order were these words presented?', pos = (0, 20))
    counter = 0
    
    probeARS = probeAR[:]
    shuffle(probeARS)

    #correct answer is choice 1

    correct = -1

    for i in range(len(probeARS)):
        if probeARS[i] == probeAR[0]:
            correct = i + 1
            
    correct = str(correct)
    new_corr = []
    new_corr.append(correct)


    option1 = psychopy.visual.TextStim(window, text='(1) ' + probeARS[0], pos = (0, -20))
    option2 = psychopy.visual.TextStim(window, text='(2) ' + probeARS[1], pos = (0, -40))    
    option3 = psychopy.visual.TextStim(window, text='(3) ' + probeARS[2], pos = (0, -60))
    option4 = psychopy.visual.TextStim(window, text='(4) ' + probeARS[3], pos = (0, -80))
    option5 = psychopy.visual.TextStim(window, text='(5) ' + probeARS[4], pos = (0, -100))
    option6 = psychopy.visual.TextStim(window, text='(6) ' + probeARS[5], pos = (0, -120))


    probe_message.draw()
    option1.draw()
    option2.draw()
    option3.draw()
    option4.draw()
    option5.draw()
    option6.draw()

    window.flip()

    answer = psychopy.event.waitKeys(keyList = ['1','2','3','4','5','6'])

 
    if answer == new_corr:
        corr = psychopy.visual.TextStim(window, text='You are correct!', pos = (0,0), height = 100)
        corr.draw()
        window.flip()
        psychopy.core.wait(display_duration)
        counter = counter + 1 #counter = 1
                                #correct on 1st attempt
        return counter
        
            
    else:
        incorrect = psychopy.visual.TextStim(window, text='Wrong choice! Try again', pos = (0,0), height = 100, wrapWidth=500000) #begin attempt 2
        incorrect.draw()
        window.flip()
        psychopy.core.wait(display_duration)
        x = int(answer[0]) - 1
        del probeARS[x]
        second_probeARS = probeARS[:]
        shuffle(second_probeARS) #new shuffled probe list
        correct2 = -1

        for i in range(len(second_probeARS)):
            if second_probeARS[i] == probeAR[0]:
                correct2 = i + 1
            
        correct2 = str(correct2)
        new_corr2 = []
        new_corr2.append(correct2)

        
        option1_2 = psychopy.visual.TextStim(window, text='(1) ' + second_probeARS[0], pos = (0, -20))
        option2_2 = psychopy.visual.TextStim(window, text='(2) ' + second_probeARS[1], pos = (0, -40))    
        option3_2 = psychopy.visual.TextStim(window, text='(3) ' + second_probeARS[2], pos = (0, -60))
        option4_2 = psychopy.visual.TextStim(window, text='(4) ' + second_probeARS[3], pos = (0, -80))
        option5_2 = psychopy.visual.TextStim(window, text='(5) ' + second_probeARS[4], pos = (0, -100))

        option1_2.draw()
        option2_2.draw()
        option3_2.draw()
        option4_2.draw()
        option5_2.draw()


        window.flip()
        
        
        answer2 = psychopy.event.waitKeys(keyList = ['1','2','3','4','5','6'])



        if answer2 == new_corr2:
            corr = psychopy.visual.TextStim(window, text='You are correct!', pos = (0,0), height = 100)
            corr.draw()
            window.flip()
            psychopy.core.wait(display_duration)
            counter = counter + 2 #counter = 2
                                #correct on 2nd attempt
            return counter
            
        else:
            incorrect = psychopy.visual.TextStim(window, text='Wrong choice! Try again', pos = (0,0), height = 100, wrapWidth=500000) #begin attempt 3
            incorrect.draw()
            window.flip()
            psychopy.core.wait(display_duration)
            y = int(answer2[0]) - 1
            del second_probeARS[y]
            third_probeARS = second_probeARS[:]
            shuffle(third_probeARS) #new shuffled probe list
            correct3 = -1

            for i in range(len(third_probeARS)):
                if third_probeARS[i] == probeAR[0]:
                    correct3 = i + 1
            
            correct3 = str(correct3)
            new_corr3 = []
            new_corr3.append(correct3)

        
            option1_3 = psychopy.visual.TextStim(window, text='(1) ' + third_probeARS[0], pos = (0, -20))
            option2_3 = psychopy.visual.TextStim(window, text='(2) ' + third_probeARS[1], pos = (0, -40))    
            option3_3 = psychopy.visual.TextStim(window, text='(3) ' + third_probeARS[2], pos = (0, -60))
            option4_3 = psychopy.visual.TextStim(window, text='(4) ' + third_probeARS[3], pos = (0, -80))

            option1_3.draw()
            option2_3.draw()
            option3_3.draw()
            option4_3.draw()


            window.flip()
        
        
            answer3 = psychopy.event.waitKeys(keyList = ['1','2','3','4','5','6'])


            if answer3 == new_corr3:
                corr = psychopy.visual.TextStim(window, text='You are correct!', pos = (0,0), height = 100)
                corr.draw()
                window.flip()
                psychopy.core.wait(display_duration)
                counter = counter + 3 #counter = 3
                                    #correct on 3rd attempt
                return counter
            
            else:
                incorrect = psychopy.visual.TextStim(window, text='Wrong choice!', pos = (0,0), height = 100, wrapWidth=500000) #begin attempt 4
                incorrect.draw()
                window.flip()
                psychopy.core.wait(display_duration)
                counter = counter + 4 #counter = 4
                                    #all incorrect
                return counter
        


def nextQuestion(window, display_duration): #screen b/w questions
    nextQ = psychopy.visual.TextStim(window, text = 'Next Question!', pos = (0,0))
    nextQ.draw()
    window.flip()
    psychopy.core.wait(display_duration)
    
def test1Mess(window, display_duration): #signal first test
    test1 = psychopy.visual.TextStim(window, text = 'Test 1', pos = (0,0), height = 100)
    test1.draw()
    window.flip()
    psychopy.core.wait(display_duration)

def test2Mess(window, display_duration): #signal second test
    test1 = psychopy.visual.TextStim(window, text = 'Test 2', pos = (0,0), height = 100)
    test1.draw()
    window.flip()
    psychopy.core.wait(display_duration)

def getScoringSheet(): #write column names on user sheet
    book = xlwt.Workbook()
    sheet1 = book.add_sheet('Sheet 1')
    sheet1.write(0,0, 'Trial #')
    sheet1.write(0,1, '1st Attempt')
    sheet1.write(0,2, '2nd Attempt')
    sheet1.write(0,3, '3rd Attempt')
    sheet1.write(0,4, 'All Incorrect')
    sheet1.write(0,5, 'Probe Type')
    sheet1.write(0,6, 'Start Time')
    sheet1.write(0,7, 'End Time')
    sheet1.write(0,8, 'Date')
    sheet1.write(0,9, 'List #')
    
    for i in range(1,73):
        sheet1.write(i,0, i)
        
    book.save('scoring_user1.xls')
    
    return sheet1, book
    

def Scoring(counter, cell, start, sheet1, book): #update scores on user sheet
    
    if counter == 1:
        start = start + 1
        sheet1.write(cell, 1, start)
    elif counter == 2:
        start = start + 1
        sheet1.write(cell, 2, start)
    elif counter == 3:
        start = start + 1
        sheet1.write(cell, 3, start)
    else:
        start = start + 1
        sheet1.write(cell, 4, start)

    book.save('scoring_user1.xls')
        
    return start, sheet1

def probeType(book, sheet1, cell, probe_i, probeAR, probeAU, probeNR, probeNU, probeFR, probeFU): #update user sheet with probe type (AR/AU...)
    if probe_i == probeAR:
        sheet1.write(cell, 5, 'AR')
    elif probe_i == probeAU:
        sheet1.write(cell, 5, 'AU')
    elif probe_i == probeNR:
        sheet1.write(cell, 5, 'NR')
    elif probe_i == probeNU:
        sheet1.write(cell, 5, 'NU')
    elif probe_i == probeFR:
        sheet1.write(cell, 5, 'FR')
    elif probe_i == probeFU:
        sheet1.write(cell, 5, 'FU')

    book.save('scoring_user1.xls')

    return sheet1

def listNum(lin, lines, sheet1, cell, book): #update user sheet with list number (1-6)
    if lin == lines[0]:
        sheet1.write(cell, 9, '1')
    elif lin == lines[1]:
        sheet1.write(cell, 9, '2')
    elif lin == lines[2]:
        sheet1.write(cell, 9, '3')
    elif lin == lines[3]:
        sheet1.write(cell, 9, '4')
    elif lin == lines[4]:
        sheet1.write(cell, 9, '5')
    elif lin == lines[5]:
        sheet1.write(cell, 9, '6')

    book.save('scoring_user1.xls')

    return sheet1
    

def Goodbye(window, display_duration, now2, sheet1, book): #update user sheet + display goodbye message on screen
    sheet1.write(1,7, now2.strftime('%H:%M'))
    goodbye = psychopy.visual.TextStim(window, text = 'You have reached the end of the experiment!', pos = (0,0), wrapWidth=50000)
    thankyou = psychopy.visual.TextStim(window, text = 'Thank you for participating!', pos = (0,-40), wrapWidth=50000)
    goodbye.draw()
    thankyou.draw()
    window.flip()
    psychopy.core.wait(display_duration)
    return sheet1
    
#-------------------------------------------------------------------------------------------------------------------------------------

#Main

def main():
    now = timeNow()
    sheet1, book = getScoringSheet()
    window = getWindow()
    display_duration, ISI = displayDuration()
    sheet1 = InstructionsStart(window, ISI, now, sheet1)
    
    lines1 = readWordList1()
    lines2 = readWordList2()
    lines3 = readWordList3()
    lines4 = readWordList4()
    lines5 = readWordList5()
    lines6 = readWordList6()

    lines, lines_shuffled = listRandomizer(lines1, lines2, lines3, lines4, lines5, lines6) #get list of word lists & randomized list of word lists


    for lin in lines_shuffled:
        stimuli, setsize = getStimuli(lin)
        AR, AU, NR, NU, FR, FU = assignCategory(stimuli)
        learningPhase(window, ISI, stimuli, setsize, display_duration)
        if lin == lines[0]: #probes from word list 1
            probeAR = getProbeAR_1()
            probeAR2 = getProbeAR_1_2()
            probeAU = getProbeAU_1()
            probeAU2 = getProbeAU_1_2()
            probeNR = getProbeNR_1()
            probeNR2 = getProbeNR_1_2()
            probeNU = getProbeNU_1()
            probeNU2 = getProbeNU_1_2()
            probeFR = getProbeFR_1()
            probeFR2 = getProbeFR_1_2()
            probeFU = getProbeFU_1()
            probeFU2 = getProbeFU_1_2()
            
        elif lin == lines[1]: #probes from word list 2
            probeAR = getProbeAR_2()
            probeAR2 = getProbeAR_2_2()
            probeAU = getProbeAU_2()
            probeAU2 = getProbeAU_2_2()
            probeNR = getProbeNR_2()
            probeNR2 = getProbeNR_2_2()
            probeNU = getProbeNU_2()
            probeNU2 = getProbeNU_2_2()
            probeFR = getProbeFR_2()
            probeFR2 = getProbeFR_2_2()
            probeFU = getProbeFU_2()
            probeFU2 = getProbeFU_2_2()
            
        elif lin == lines[2]: #probes from word list 3
            probeAR = getProbeAR_3()
            probeAR2 = getProbeAR_3_2()
            probeAU = getProbeAU_3()
            probeAU2 = getProbeAU_3_2()
            probeNR = getProbeNR_3()
            probeNR2 = getProbeNR_3_2()
            probeNU = getProbeNU_3()
            probeNU2 = getProbeNU_3_2()
            probeFR = getProbeFR_3()
            probeFR2 = getProbeFR_3_2()
            probeFU = getProbeFU_3()
            probeFU2 = getProbeFU_3_2()


        elif lin == lines[3]: #probes from word list 4
            probeAR = getProbeAR_4()
            probeAR2 = getProbeAR_4_2()
            probeAU = getProbeAU_4()
            probeAU2 = getProbeAU_4_2()
            probeNR = getProbeNR_4()
            probeNR2 = getProbeNR_4_2()
            probeNU = getProbeNU_4()
            probeNU2 = getProbeNU_4_2()
            probeFR = getProbeFR_4()
            probeFR2 = getProbeFR_4_2()
            probeFU = getProbeFU_4()
            probeFU2 = getProbeFU_4_2()



        elif lin == lines[4]: #probes from word list 5
            probeAR = getProbeAR_5()
            probeAR2 = getProbeAR_5_2()
            probeAU = getProbeAU_5()
            probeAU2 = getProbeAU_5_2()
            probeNR = getProbeNR_5()
            probeNR2 = getProbeNR_5_2()
            probeNU = getProbeNU_5()
            probeNU2 = getProbeNU_5_2()
            probeFR = getProbeFR_5()
            probeFR2 = getProbeFR_5_2()
            probeFU = getProbeFU_5()
            probeFU2 = getProbeFU_5_2()



        elif lin == lines[5]: #probes from word list 6
            probeAR = getProbeAR_6()
            probeAR2 = getProbeAR_6_2()
            probeAU = getProbeAU_6()
            probeAU2 = getProbeAU_6_2()
            probeNR = getProbeNR_6()
            probeNR2 = getProbeNR_6_2()
            probeNU = getProbeNU_6()
            probeNU2 = getProbeNU_6_2()
            probeFR = getProbeFR_6()
            probeFR2 = getProbeFR_6_2()
            probeFU = getProbeFU_6()
            probeFU2 = getProbeFU_6_2()

    
        probes, probes_shuffled = randCat(probeAR, probeAU, probeNR, probeNU, probeFR, probeFU)
    
        test1Mess(window, display_duration) #TEST 1

        cell = 0

        for i in range(len(probes_shuffled)):
            start = 0
            probe_i = probes_shuffled[i]
            counter = probeTrial(window, ISI, display_duration, probe_i)
            cell = cell + 1
            start, sheet1 = Scoring(counter, cell, start, sheet1, book)
            sheet1 = probeType(book, sheet1, cell, probe_i, probeAR, probeAU, probeNR, probeNU, probeFR, probeFU) #add probe type to scoring sheet
            sheet1 = listNum(lin, lines, sheet1, cell, book)#Add list number to scoring sheet
            if (i+1) < 5:
                nextQuestion(window, display_duration)
            else:
                print('End of Test 1')
        
        test2Mess(window, display_duration) #TEST 2

        probes, probes_shuffled = randCat(probeAR2, probeAU2, probeNR2, probeNU2, probeFR2, probeFU2)
        
        for i in range(len(probes_shuffled)):
            start = 0
            probe_i = probes_shuffled[i]
            counter = probeTrial(window, ISI, display_duration, probe_i)
            cell= cell + 1
            start, sheet1 = Scoring(counter, cell, start, sheet1, book)
            sheet1 = probeType(book, sheet1, cell, probe_i, probeAR2, probeAU2, probeNR2, probeNU2, probeFR2, probeFU2) #add probe type to scoring sheet
            sheet1 = listNum(lin, lines, sheet1, cell, book) #Add list number to scoring sheet
            if (i+1) < 5:
                nextQuestion(window, display_duration)
            else:
                print('End of Test 2')


    now2 = timeNow()
    sheet1 = Goodbye(window, display_duration, now2, sheet1, book)
    book.save('scoring_user1.xls')

    window.close()
    


#Functions related to word lists and probe lists -----------------------------------------------------------------------------------------------------------------------------

#READ WORD LISTS 1 THRU 6 


def readWordList1():
    wordlist = open('word_list_1.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines

def readWordList2():
    wordlist = open('word_list_2.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines

def readWordList3():
    wordlist = open('word_list_3.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines

def readWordList4():
    wordlist = open('word_list_4.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines


def readWordList5():
    wordlist = open('word_list_5.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines


def readWordList6():
    wordlist = open('word_list_6.txt','r')
    lines = wordlist.readlines()
    wordlist.close
    return lines


def listRandomizer(lines1, lines2, lines3, lines4, lines5, lines6):
    lines = []
    lines.append(lines1)
    lines.append(lines2)
    lines.append(lines3)
    lines.append(lines4)
    lines.append(lines5)
    lines.append(lines6)
    lines_shuffled = lines[:]
    shuffle(lines_shuffled)
    return lines, lines_shuffled
    
    


#--------------------------------------------------------------------------------------------------------------------

#GET PROBE LISTS

#ADJACENT & RELATED (AR)


def getProbeAR_1():
    probelist = open('probe_list_AR_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_1_2():
    probelist = open('probe_list_AR_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_2():
    probelist = open('probe_list_AR_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_2_2():
    probelist = open('probe_list_AR_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_3():
    probelist = open('probe_list_AR_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_3_2():
    probelist = open('probe_list_AR_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_4():
    probelist = open('probe_list_AR_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_4_2():
    probelist = open('probe_list_AR_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR


def getProbeAR_5():
    probelist = open('probe_list_AR_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_5_2():
    probelist = open('probe_list_AR_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR


def getProbeAR_6():
    probelist = open('probe_list_AR_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR

def getProbeAR_6_2():
    probelist = open('probe_list_AR_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAR = []
    for line in p_lines:
        line = line.strip()
        probeAR.append(line)
    return probeAR


#ADJACENT & UNRELATED (AU) ------------------------------------------------------------------------------------------------


def getProbeAU_1():
    probelist = open('probe_list_AU_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_1_2():
    probelist = open('probe_list_AU_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


def getProbeAU_2():
    probelist = open('probe_list_AU_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


def getProbeAU_2_2():
    probelist = open('probe_list_AU_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


def getProbeAU_3():
    probelist = open('probe_list_AU_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_3_2():
    probelist = open('probe_list_AU_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_4():
    probelist = open('probe_list_AU_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_4_2():
    probelist = open('probe_list_AU_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


def getProbeAU_5():
    probelist = open('probe_list_AU_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_5_2():
    probelist = open('probe_list_AU_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


def getProbeAU_6():
    probelist = open('probe_list_AU_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU

def getProbeAU_6_2():
    probelist = open('probe_list_AU_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeAU = []
    for line in p_lines:
        line = line.strip()
        probeAU.append(line)
    return probeAU


#------------------------------------------------------------------------------------------------------------------------------------------------

#NEAR & RELATED (NR)


def getProbeNR_1():
    probelist = open('probe_list_NR_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR

def getProbeNR_1_2():
    probelist = open('probe_list_NR_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_2():
    probelist = open('probe_list_NR_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_2_2():
    probelist = open('probe_list_NR_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_3():
    probelist = open('probe_list_NR_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR



def getProbeNR_3_2():
    probelist = open('probe_list_NR_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_4():
    probelist = open('probe_list_NR_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_4_2():
    probelist = open('probe_list_NR_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR

def getProbeNR_5():
    probelist = open('probe_list_NR_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_5_2():
    probelist = open('probe_list_NR_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_6():
    probelist = open('probe_list_NR_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


def getProbeNR_6_2():
    probelist = open('probe_list_NR_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNR = []
    for line in p_lines:
        line = line.strip()
        probeNR.append(line)
    return probeNR


#-------------------------------------------------------------------------------------------------------------------------------------------------

#NEAR & UNRELATED (NU)



def getProbeNU_1():
    probelist = open('probe_list_NU_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

def getProbeNU_1_2():
    probelist = open('probe_list_NU_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

def getProbeNU_2():
    probelist = open('probe_list_NU_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

def getProbeNU_2_2():
    probelist = open('probe_list_NU_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_3():
    probelist = open('probe_list_NU_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_3_2():
    probelist = open('probe_list_NU_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_4():
    probelist = open('probe_list_NU_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_4_2():
    probelist = open('probe_list_NU_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_5():
    probelist = open('probe_list_NU_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

def getProbeNU_5_2():
    probelist = open('probe_list_NU_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU


def getProbeNU_6():
    probelist = open('probe_list_NU_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

def getProbeNU_6_2():
    probelist = open('probe_list_NU_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeNU = []
    for line in p_lines:
        line = line.strip()
        probeNU.append(line)
    return probeNU

#------------------------------------------------------------------------------------------------------------------------------------------------------

#FAR & RELATED (FR)

def getProbeFR_1():
    probelist = open('probe_list_FR_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_1_2():
    probelist = open('probe_list_FR_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_2():
    probelist = open('probe_list_FR_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_2_2():
    probelist = open('probe_list_FR_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_3():
    probelist = open('probe_list_FR_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR


def getProbeFR_3_2():
    probelist = open('probe_list_FR_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR


def getProbeFR_4():
    probelist = open('probe_list_FR_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR


def getProbeFR_4_2():
    probelist = open('probe_list_FR_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR


def getProbeFR_5():
    probelist = open('probe_list_FR_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_5_2():
    probelist = open('probe_list_FR_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR


def getProbeFR_6():
    probelist = open('probe_list_FR_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

def getProbeFR_6_2():
    probelist = open('probe_list_FR_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFR = []
    for line in p_lines:
        line = line.strip()
        probeFR.append(line)
    return probeFR

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#FAR & UNRELATED (FU)

def getProbeFU_1():
    probelist = open('probe_list_FU_1.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_1_2():
    probelist = open('probe_list_FU_1_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_2():
    probelist = open('probe_list_FU_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_2_2():
    probelist = open('probe_list_FU_2_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_3():
    probelist = open('probe_list_FU_3.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU

def getProbeFU_3_2():
    probelist = open('probe_list_FU_3_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_4():
    probelist = open('probe_list_FU_4.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_4_2():
    probelist = open('probe_list_FU_4_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_5():
    probelist = open('probe_list_FU_5.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_5_2():
    probelist = open('probe_list_FU_5_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_6():
    probelist = open('probe_list_FU_6.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


def getProbeFU_6_2():
    probelist = open('probe_list_FU_6_2.txt','r')
    p_lines = probelist.readlines()
    probelist.close
    probeFU = []
    for line in p_lines:
        line = line.strip()
        probeFU.append(line)
    return probeFU


#--------------------------------------------------------------------------------------------------------------------------------------------------------

#OTHER

def assignCategory(stimuli): #assign probe category
    AR = [] #adjacent & related
    AR.append(stimuli[22])
    AR.append(stimuli[23])
    AR.append(stimuli[24])

    AU = [] #adjacent & unrelated
    AU.append(stimuli[28])
    AU.append(stimuli[29])
    AU.append(stimuli[30])

    NR = [] #near & related
    NR.append(stimuli[7])
    NR.append(stimuli[11])
    NR.append(stimuli[15])
    
    NU = [] #near & unrelated
    NU.append(stimuli[6])
    NU.append(stimuli[10])
    NU.append(stimuli[14])

    FR = [] #far & related
    FR.append(stimuli[5])
    FR.append(stimuli[21])
    FR.append(stimuli[37])

    FU = [] #far & unrelated
    FU.append(stimuli[4])
    FU.append(stimuli[20])
    FU.append(stimuli[36])
    
    return AR, AU, NR, NU, FR, FU



def randCat(probeAR, probeAU, probeNR, probeNU, probeFR, probeFU): #randomize probe category
    probes = []
    probes.append(probeAR)
    probes.append(probeAU)
    probes.append(probeNR)
    probes.append(probeNU)
    probes.append(probeFR)
    probes.append(probeFU)
    probes_shuffled = probes[:]
    shuffle(probes_shuffled)
    return probes, probes_shuffled




main()
